
#include "Thread.hpp"
#include "ThreadPool.hpp"
#include "Log.hpp"
#include "Task.hpp"
#include <iostream>
#include <string>
#include <memory>
#include <ctime>
using namespace std;

int main()
{
    srand((unsigned int)time(nullptr));

    EnableScreen();//日志消息输出到显示器
    //EnableFile();//日志消息输出到log.txt
    //unique_ptr<ThreadPool<int>> tp=make_unique<ThreadPool<int>>();//c++14
    unique_ptr<ThreadPool<Task>> tp(new ThreadPool<Task>(5));//c++11
    tp->InitThreadPool();
    //1.启动线程池
    tp->Start();


    //2.投放任务
    int tasknum=10;
    while(tasknum)
    {
        int a=rand()%10+1;
        usleep(1000);
        int b=rand()%20+1;
        Task t(a,b);
        LOG(INFO,"main thread push task:%s",t.DebugToString().c_str());
        tp->EnQueue(t);
        sleep(1);
        tasknum--;
    }

    tp->Stop();
    //3.回收线程池内部的线程
    tp->Wait();
    return 0;
}